package com.ruoyi.client;

import com.ruoyi.system.domian.jpa.CdUserJpa;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.exception.TokenRuntimeException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author Dale Mao    ---多多 Email:453918229@qq.com
 * @description BaseOpenController
 * @date 2021-01-26 15:33
 */
public class BaseOpenController extends BaseController {


    protected CdUserJpa getCdUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (! (authentication.getPrincipal() instanceof  CdUserJpa)) {
            throw new TokenRuntimeException("token 用户身份和操作类型所需身份不符合");
        }
        return (CdUserJpa) authentication.getPrincipal();
    }


}
